#include "GraphicsFramework.h"

_OpenGLFramework::_OpenGLFramework()
{
	MainWindow = NULL;
	CfgFileName = "";
	running = false;
}

_OpenGLFramework::_OpenGLFramework(std::string nCfgFileName)
{
	SetCfgFileName(nCfgFileName);
	MainWindow = NULL;
	running = false;

	if(!ReinitializeWindow())
	{
		MainWindow = NULL;
	}
	else
	{
		running = true;
	}

}

_OpenGLFramework::~_OpenGLFramework()
{
	if(MainWindow)
	{
		MainWindow->close();
		delete MainWindow;
		MainWindow = NULL;
	}

	delete Test;
}

bool _OpenGLFramework::LoadGameEntities( void )
{
	Test = new Entity(sf::Vector2f(300,300), sf::Vector2f(0,0), 0, 90.f, GameGlobals->GetTexture(2), MainWindow);
	return true;
}

void _OpenGLFramework::SetCfgFileName( std::string nCfgFileName )
{
	CfgFileName = nCfgFileName;
}

bool _OpenGLFramework::ReinitializeWindow( void )
{
	WindowSettings NewWindowSettings = GetWindowSettings(CfgFileName);
	
	if(MainWindow == NULL)
	{
		MainWindow = new sf::RenderWindow();
	}
	if(MainWindow == NULL)
		return false;

	MainWindow->create(NewWindowSettings.MainMode, NewWindowSettings.WindowTitle,
	/*---------------*/NewWindowSettings.WindowStyle, NewWindowSettings.MainWindowSettings);
	
	return true;
}

void _OpenGLFramework::Render( void )
{
	MainWindow->clear(sf::Color(0,0,0,255));
	Test->Render();
	MainWindow->display();
}

void _OpenGLFramework::Update(float dt)
{
	Test->Update(dt);
}

bool _OpenGLFramework::Running( void )
{
	return running;
}

void _OpenGLFramework::SetRunning( bool nRunning )
{
	running = nRunning;
}

sf::RenderWindow* _OpenGLFramework::GetRenderWindowPtr( void )
{
	return MainWindow;
}